<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/jsp/taglib.jsp"%>
<%@ page import="com.framework.utils.ConfigUtil" %>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>信息编辑窗体</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

   <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <%--<link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">--%>
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/plugins/h+/css/plugins/webuploader/webuploader.css">
    <link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">

    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/switchery/switchery.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">

<style>
    .dtupload>img{
        width: 54px;
        padding-left: 39px;
        padding-top: 16px;
    }
    .dtupload>a{
        color: #268eff;
        font-size: 12px;
        position: relative;
        left: 26px;
        top: 10px;
    }.dtupload>a:hover,
     .shoplogo>a:hover{
         color:#F93;
     }.upload_pic {
          height: 70px;
          width:70px;
          position: relative;
          cursor: pointer;
          color: #ccbe9e;
          background: #fff;
          overflow: hidden;
          display: inline-block;
          *display: inline;
          *zoom: 1;
      }
    .upload_pic input {
        position: absolute;
        height:100%;
        width:100%;
        right: 0;
        top: 0;
        opacity: 0;
        filter: alpha(opacity=0);
        cursor: pointer
    }
    .upload_pic:hover {
        color: #ccbe9e;
        background: #fff;
        text-decoration: none
    }
    .posabs{
        position: absolute;
        right: 23px;
        top: 9px;
    }
</style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="panel-options">
        <ul class="nav nav-tabs">
            <li class="active"><a data-toggle="tab" href="tabs_panels.html#tab-0"><i class="fa fa-laptop">商户设置</i></a>
            </li>
        </ul>
    </div>

    <div class="panel-body">
        <form class="form-horizontal" onsubmit="return  false" id="form_brand">
        <input type="hidden" id="pbrand_brand_code" name="pbrand.brandCode" value="${id}">
        <input type="hidden" id="pbrand_type" name="pbrand.type" >
        <input type="hidden" id="pbrand_oldPhone" >
        <div class="tab-content">
            <div id="tab-0" class="tab-pane active">
                <div class="ibox-content">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商户LOGO：</label>
                            <div class="col-sm-4">
                                <!--上传logo-->
                                <div class="dtupload">
                                <a href="javascript:" class="upload_pic" style="height:80px;"><input type="file" name="fileToUpload" id="fileToUpload1" onChange="uploadFile('fileToUpload1','imgUpdate','shopPicId');">
                                    <img  id="imgUpdate" src="${pageContext.request.contextPath}/resources/image/logopic1.png" width="100%"/>
                                    <input type="hidden" id="shopPicId" name="pbrand.logoUrl">
                                </a>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">登录名：</label>
                            <div class="col-sm-9">
                                <input type="text" placeholder="登录名" class="form-control" id="pbrand_loginName" name="pbrand.loginName">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商户名称：</label>
                            <div class="col-sm-9">
                                <input type="text" placeholder="用户名" class="form-control" id="pbrand_name" name="pbrand.name">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">联系方式：</label>
                            <div class=" col-sm-9">
                                <input type="number" id="pbrand_telephone"  name="pbrand.telephone" placeholder="请输入手机号码" class="form-control">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">详细地址：</label>
                            <div class=" col-sm-9">
                                <input type="text" id="pbrand_address"  name="pbrand.address" placeholder="请输入详细地址" class="form-control">
                            </div>
                        </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">备注：</label>
                        <div class=" col-sm-9">
                            <textarea type="text" id="pbrand_introduction"  name="pbrand.introduction" placeholder="请填写描述" class="form-control"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-3 col-sm-8">
                            <button class="btn btn-primary" onclick="doSubmit();">提交</button>
                            <button id="btn_close1"  class="btn btn-primary" type="button">关闭</button>
                        </div>
                    </div>
                </div>

            </div>
        </div>
        </form>

        </div>
</div>

</body>
    <script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>

<!-- 配置文件 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/utf8-jsp/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/utf8-jsp/ueditor.all.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/demo/form-validate-demo.min.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/layer2.4/layer.js"></script>

    <script src="${ctxStatic}/plugins/h+/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/chosen/chosen.jquery.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/jsKnob/jquery.knob.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/jasny/jasny-bootstrap.min.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/nouslider/jquery.nouislider.min.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/switchery/switchery.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/ionRangeSlider/ion.rangeSlider.min.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/iCheck/icheck.min.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/clockpicker/clockpicker.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/cropper/cropper.min.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/demo/form-advanced-demo.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ajaxfileupload.js"></script>

<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/ueditor.config.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/ueditor.all.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/lang/zh-cn/zh-cn.js"></script>


<script type="text/javascript">

</script>

    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<script type="text/javascript">

    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    var picPath='<%=ConfigUtil.get("OSSURL")%>';
    var id='${id}';
    if(id!=null&&id!=''){
        $("#pbrand_type").val("1");
        loadForEdit(id);
    }else{
        $("#pbrand_type").val("0");
    }
    //编辑回写
    function loadForEdit(id) {
       var url="${ctx}/merchant/getById.ac";
        $.ajax({
            url:url,
            data:{id:id},
            type:'post',
            cache:false,
            dataType:'json',
            success:function(data) {
                $("#pbrand_name").val(data.name);
                $("#pbrand_loginName").val(data.loginName);
                $("#pbrand_telephone").val(data.telephone);
                $("#pbrand_address").val(data.address);
                $("#pbrand_introduction").val(data.introduction);
                $("#imgUpdate").attr("src",picPath+data.logo_url);
                $("#shopPicId").val(data.logo_url);
                $("#pbrand_oldPhone").val(data.loginName);
            },
            error : function() {
                alert("异常！");
            }
        });
    }


    //关闭iframe
    $('#btn_close').click(function(){
        parent.layer.close(index);
    });
    //关闭iframe
    $('#btn_close1').click(function(){
        parent.layer.close(index);
    });
    function doSubmit()//提交保存
    {

        var name=$("#pbrand_name").val();//名称
        var logo=$("#shopPicId").val();//logo
        var address=$("#pbrand_address").val();//地址
        var phone=$("#pbrand_telephone").val();//联系方式
        var introduction=$("#pbrand_introduction").val();
        var loginName=$("#pbrand_loginName").val();
        var oldName=$("#pbrand_oldPhone").val();
        var isOk=true;
        if(logo==null||logo==undefined||logo==''){alert("请上传商户logo");isOk= false;}
        if(name==null||name==undefined||name==''){alert("请输入商户名称");isOk= false;}
        if(loginName==null||loginName==undefined||loginName==''){alert("请输入商户登录名");isOk= false;}
        if(phone==null||phone==undefined||phone==''){alert("请输入联系方式");isOk= false;}
        if(address==null||address==undefined||address==''){alert("请输入详细地址");isOk= false;}
        if(introduction==null||introduction==undefined||introduction==''){alert("请输入备注");isOk= false;}
        if(isOk){
            if(loginName==oldName){
                saveOrUpdate();
            }else{
            $.ajax( {
                url:'${pageContext.request.contextPath}/merchant/checkLoginName.ac?loginName='+loginName,// 跳转到 action
                type:'post',
                cache:false,
                dataType:'json',
                success:function(data) {
                    if(data=="0"){
                        saveOrUpdate();
                    }else{
                        alert("登录名重复，请重新输入");
                    }

                },
                error : function() {
                    alert("操作失败！");
                }
            });
            }
        }else
        {
            return false;
        }
    }

    function saveOrUpdate() {
        $.ajax( {
            url:'${pageContext.request.contextPath}/merchant/doSave.ac',// 跳转到 action
            data:$("#form_brand").serialize(),
            type:'post',
            cache:false,
            dataType:'json',
            success:function(data) {

                if(data=="success")
                {
                    alert("操作成功！");

                    parent.layer.close(index);
                    parent.queryParams();
                }else
                {
                    alert("操作失败！");
                }
            },
            error : function() {
                alert("操作失败！");
            }
        });
    }


   // var picPath='http://9900oss.oss-cn-hangzhou.aliyuncs.com/';

    function uploadFile(obj,id,picId){//上传图片
        var labid = "";
        //var detailId = $("#detailId").val();
        //$("#"+id).css("background","url(${pageContext.request.contextPath}/resources/assets/images/waiting.gif) no-repeat 0 0/100% 100%");
        $.ajaxFileUpload({
            url: '${pageContext.request.contextPath}/common/doUploadFile.ac',
            secureuri: false,
            type:'post',
            fileElementId: obj,
            dataType: 'text',
            success: function(data, status) {

                var img=JSON.parse(data);
                $("#"+id).attr("src",picPath+img.path);
                $("#"+picId).val(img.path);

            },
            error: function(data, status, e) {
                alert(e);
            }
        });
    }
    
    
    function checkNumber(obj) {
        var reg=/^[0-9]{1,}(?:.[0-9]{0,2})?$/;

        if(!reg.test(obj.value))
        {
            alert("请正确输入数字,且保留小数点后2位");
            obj.value="0.0";
        }
    }


    function showOrhideOpetion(){
        if($("#pbrand_is_periodization").is(':checked')){
            $("#period").show();
            $("#periodization_hide").val(1);
        }else{
            $("#period").hide();
            $("#periodization_hide").val(0);
        }
    }


    $(function(){
        $("#form_brand").validate();
        initPeriod();
    });

    //初始化分配table行号
    function initPeriod(){
        $("#period_table tbody").find("tr").each(function(){
            var row_num =$(this).prevAll().length + 1;//行号
            $(this).children("td:first").html(row_num);
        });
    }


    function addRow(){
        var row_num = $("#period_table tbody tr:last").prevAll().length+2;
        var tr ='<tr>'
                +'<td>'+row_num+'</td>'
                +'<td><input type="number" name="scale" onkeyup= "if( !/^[1-9][0-9]$|^[0-9]$|^0$/.test(this.value)){alert(\'请输入0-100的整数\');this.value=\'\';}" ></td>'
                +'<td>'
                +'<a id="deleteRow" class="edit ml10" href="javascript:void(0);" onClick="deleteRow(this);" title="删除本行">'
                +'<i class="glyphicon glyphicon-minus"></i>'
                +'</a></td></tr>';
        $("#period_table tbody tr:last").after(tr);
    }

    function deleteRow(obj){
        $(obj).parent().parent().remove();
        initPeriod();
    }
</script>

</html>

